package com.example.oneSpringMVC.exception;

import com.example.oneSpringMVC.common.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @description: 全局异常拦截器
 * @author: xinTong
 * @create: 2024-01-24 10:22
 **/
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(RuntimeException.class)
    public Result handler(RuntimeException e){
        e.printStackTrace();
        return Result.fail("系统异常");
    }

    // 获取异常信息
    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Result handler1(RuntimeException e){
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }
}
